package corbaEventService;

import org.omg.CORBA.Object;
import org.omg.PortableServer.POAPackage.ServantNotActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;

import cosEventChannelAdmin.EventChannel;
import cosEventChannelAdmin.ProxyPullConsumer;
import cosEventChannelAdmin.ProxyPullConsumerHelper;
import cosEventChannelAdmin.ProxyPushConsumer;
import cosEventChannelAdmin.SupplierAdminPOA;

public class SupplierAdminImpl extends SupplierAdminPOA {
	private EventChannel channel;
	private ProxyPullConsumer proxyPullConsumer;
	

	public SupplierAdminImpl(EventChannel channel) {
		super();
		this.channel = channel;
	}

	@Override
	public ProxyPushConsumer obtain_push_consumer() {		
		return null;
	}

	@Override
	public ProxyPullConsumer obtain_pull_consumer() {
		initProxyPullConsumer();
		return proxyPullConsumer;
	}

	private void initProxyPullConsumer(){
		if(proxyPullConsumer == null){
			ProxyPullConsumerImpl proxyPullConsumerImpl = new ProxyPullConsumerImpl(channel);
			Object ref = null;
			try {
				ref = _poa().servant_to_reference(proxyPullConsumerImpl);
			} catch (ServantNotActive e) {				
				e.printStackTrace();
			} catch (WrongPolicy e) {				
				e.printStackTrace();
			}
			proxyPullConsumer = ProxyPullConsumerHelper.narrow(ref);
		}
	}
}
